import marimo

__generated_with = "0.9.27"
app = marimo.App(width="full")


@app.cell
def __():
    2.54*1.5


    27.7, 28.2
    return


@app.cell
def __():
    import marimo as mo
    a_ui = mo.ui.slider(start=1, stop=100, label='set a:')
    a_ui
    return a_ui, mo


@app.cell
def __(a_ui):
    b = a_ui.value + 1
    b
    return (b,)


@app.cell
def __(mo):
    s = mo.ui.datetime()
    s
    return (s,)


@app.cell
def __(s):
    s.value
    return


@app.cell
def __(mo):
    sb = mo.ui.date()
    sb
    return (sb,)


@app.cell
def __(sb):
    sb.value
    return


@app.cell
def __(mo):
    # 此处是markdown文本，不用f字符串

    user_info = mo.md('''
        - 你叫什么名字？:{name}
        - 你什么时候出生？:{birthday}
        ''').batch(
        name=mo.ui.text(), 
        birthday=mo.ui.date()
    )
    user_info
    return (user_info,)


@app.cell
def __(mo):
    login_box = mo.md('''
    - username: {name}
    - password: {passwd}
    ''').batch(
        name = mo.ui.text(placeholder='用户名'),  #文本框显示 用户名
        passwd = mo.ui.text(kind='password'),  #文本框显示锁
        # name = mo.ui.text(), 
        # passwd = mo.ui.text(), 
    ).form() #增加一个提交按钮

    # 老是忘了输入这个导致不显示
    login_box
    return (login_box,)


@app.cell
def __(login_box):
    login_box.value
    return


@app.cell
def __():
    account = {
        'guest': 'guest',
        'root': '123456'
    }
    # type(account)
    return (account,)


@app.cell
def __(account, mo):
    # 形参名必须和md文本中一致，不然报错

    def check_login(name, passwd):
        if name in account and passwd == account[name]:
            mo.status.toast('登陆成功！')  #提示信息
            return True

        mo.status.toast('用户名或密码错误！', kind='danger') #kind，提示的样式
        return False


    # def check_login(username, password):
    #     if username in account and password == account[username]:
    #         return True
    #     return False

    # # 调用时解包并重命名
    # check_login(username=login_box.value['name'], password=login_box.value['passwd'])
    return (check_login,)


@app.cell
def __(check_login, login_box):

    # login_box文本框中必须有值，不然报错

    check_login(**login_box.value)


    return


@app.cell
def __(mo):
    mo.md(r"""## 字典的ui""")
    return


@app.cell
def __(mo):
    tea_ui = mo.ui.dictionary({
        '品种': mo.ui.dropdown(options=['手打柠檬茶', '抹茶拿铁', '巴黎气泡水']),
        '数量': mo.ui.number(start=0, stop=5, value=0), #value,默认值
        '甜度': mo.ui.radio(options=['正常甜', '少糖', '少少糖', '不加糖'], inline=True),
        '冰度': mo.ui.radio(options=['正常冰', '少冰', '去冰', '热']),
    })
    tea_ui
    return (tea_ui,)


@app.cell
def __(mo, tea_ui):

    _t = tea_ui.value

    _kind, _amount, _sweet, _icy = _t['品种'], _t['数量'], _t['甜度'], _t['冰度']

    if _amount > 0:
        msg = f'您点了{_amount}杯{_kind}，{_sweet}，{_icy}！'

    else:
        msg = '您还没有点单。'

    mo.md(msg)

    return (msg,)


@app.cell
def __(mo, tea_ui):
    mo.ui.table(tea_ui.value)
    return


@app.cell
def __(mo, tea_ui):


    n = 3

    many_tea_ui = mo.ui.array([tea_ui]*n)
    many_tea_ui
    return many_tea_ui, n


@app.cell
def __(many_tea_ui, mo):
    mo.ui.table(many_tea_ui.value)
    return


if __name__ == "__main__":
    app.run()
